﻿Imports System.Text.RegularExpressions

Public Class Mini
    Dim X, Y As Integer
    Private BP As Bitmap
    Dim FT As Font = New Font("幼圆", 26, FontStyle.Regular, GraphicsUnit.Pixel)
    Private SecondStringBP As Bitmap
    ''' <summary>
    ''' 显示歌词
    ''' </summary>
    ''' <param name="MusicText">歌曲语句</param>
    ''' <param name="s">进度百分比</param>
    ''' <remarks></remarks>
    Public Sub ShowLrc(ByVal MusicText As String, ByVal s As Double)
        BP = New Bitmap(Me.Width, Me.Height)
        Using G As Graphics = Graphics.FromImage(BP)
            G.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            G.CompositingMode = Drawing2D.CompositingMode.SourceOver
            G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
            X = 20 : Y = 20
            Dim per As Integer = 80
            per = IIf(ownChinese(MusicText) = False, 80, 30)
            For l As Integer = 1 To Math.Ceiling(Strings.Len(MusicText) / per)
                Dim nowWord = Mid(MusicText, (l - 1) * per + 1, per)
                For J As Integer = 1 To 5
                    Using lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, 1), Color.FromArgb(90 - 90 / 5 * J, 0, 0, 0), Color.FromArgb(100 - J * 20, 0, 0, 0))
                        G.DrawString(nowWord, FT, lg, X + J, Y + J)
                    End Using
                Next
                For I As Integer = 1 To 3
                    Using lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, 1), Color.FromArgb(90 - 90 / 3 * I, 0, 0, 0), Color.FromArgb(90 - 90 / 3 * I, 0, 0, 0))
                        G.DrawString(nowWord, FT, lg, X - I, Y)
                        G.DrawString(nowWord, FT, lg, X - I, Y - I)
                        G.DrawString(nowWord, FT, lg, X, Y - I)
                        G.DrawString(nowWord, FT, lg, X + I, Y - I)
                        G.DrawString(nowWord, FT, lg, X + I, Y)
                        G.DrawString(nowWord, FT, lg, X + I, Y + I)
                        G.DrawString(nowWord, FT, lg, X, Y + I)
                        G.DrawString(nowWord, FT, lg, X - I, Y + I)
                    End Using
                Next
                Using lg As New Drawing2D.LinearGradientBrush(New Point(X, Y), New Point(X, Y + FT.Height), Color.GreenYellow, Color.DarkOrange)
                    G.DrawString(nowWord, FT, lg, X, Y)
                End Using
                Y += 30
            Next

            'G.DrawImage(GetStringImage(MusicText), New Rectangle(0, 0, Me.Width * s, Me.Height), New Rectangle(0, 0, Me.Width * s, Me.Height), GraphicsUnit.Pixel)
        End Using
        Me.BackgroundImage = BP
        DrawBP(Me, BP, 255)
    End Sub


    Private Function ownChinese(ByVal str As String) As Boolean
        Dim regX As New Regex("[\u4e00-\u9fa5]")
        If regX.IsMatch(str) Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Function GetStringImage(ByVal s As String) As Bitmap
        If SecondStringBP IsNot Nothing Then SecondStringBP.Dispose()
        SecondStringBP = New Bitmap(Me.Width, Me.Height)
        Using G As Graphics = Graphics.FromImage(SecondStringBP)
            G.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            G.CompositingMode = Drawing2D.CompositingMode.SourceOver
            G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
            Using lg As New Drawing2D.LinearGradientBrush(New Point(X, Y), New Point(X, Y + FT.Height), Color.LightYellow, Color.Red)
                G.DrawString(s, FT, lg, X, Y)
            End Using
        End Using
        Return SecondStringBP
    End Function
    Private Sub Mini_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Left = (My.Computer.Screen.Bounds.Size.Width - Me.Width) / 2
        Me.Top = (My.Computer.Screen.Bounds.Size.Height - Me.Height - 50)
    End Sub

    Private Sub Mini_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If no_remove = False Then
            ReleaseCapture()
            SendMessage(Me.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0)
        End If
    End Sub

    Private Sub Mini_Click(sender As Object, e As EventArgs) Handles Me.Click

    End Sub

    Private Sub Mini_DoubleClick(sender As Object, e As EventArgs) Handles Me.DoubleClick
        Me.Hide()
        main_window.singleModel = False
        main_window.show()
    End Sub

    Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or &H80000
            Return cp
        End Get
    End Property
End Class